package com.martin.dsc.mine;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

public class Test {
    public static void main(String[] args) {
        // 构建商品列表
        Item item1 = new Item("P001", 2);
        Item item2 = new Item("P002", 1);
        List<Item> items = Arrays.asList(item1, item2);

        // 使用建造者模式创建订单
        Order order = new Order.OrderBuilder()
                .setOrderId("O1001")
                .setUserId("U123")
                .setItems(items)
                .setStatus(OrderStatus.CREATED)
                .setCreateTime(LocalDateTime.now())
                .build();

        // 获取订单管理器单例
        OrderManager manager = OrderManager.getInstance();
        // 创建订单
        manager.createOrder(order);

        // 获取所有订单
        List<Order> allOrders = manager.getAllOrders();
        System.out.println("所有订单数量: " + allOrders.size());
        for (Order o : allOrders) {
            System.out.println("订单号: " + o.getOrderId() + ", 用户ID: " + o.getUserId() + ", 状态: " + o.getStatus());
        }

        // 根据订单号获取订单
        Order found = manager.getOrderById("O1001");
        System.out.println("查找订单O1001: " + (found != null ? "找到" : "未找到"));
    }
}
